package com.gxar.quick.ar.server.base.controller;

import com.gxar.common.entity.PageResult;
import com.gxar.common.entity.Result;
import com.gxar.common.entity.login.LoginUserThread;
import com.gxar.common.entity.login.UserProfile;
import com.gxar.quick.ar.server.base.model.exchange.vo.response.AdminExchangeItemStatisticsResponse;
import com.gxar.quick.ar.server.base.model.exchange.vo.response.AdminExchangeItemTransferPageResponse;
import com.gxar.quick.ar.server.base.model.exchange.vo.response.AdminExchangeItemTransferTopPageResponse;
import com.gxar.quick.ar.server.db.service.ExchangeItemRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author linsy
 * @version 1.0
 * @created 2024/2/29 16:30
 */
@Api(tags = "管理端兑换品记录接口")
@RestController
@RequestMapping("/admin/api/exchange-item/record")
@RequiredArgsConstructor
@Slf4j
public class AdminExchangeItemRecordController {

    private final ExchangeItemRecordService recordService;


    @ApiOperation("转赠/赠送记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page_num", value = "页码", dataType = "number"),
            @ApiImplicitParam(name = "page_size", value = "页记录数", dataType = "number"),
            @ApiImplicitParam(name = "type", value = "赠送类型 1-转赠，2-赠送", dataType = "number"),
    })
    @GetMapping("/transfer")
    public Result<PageResult<AdminExchangeItemTransferPageResponse>> transferRecordPage(@RequestParam(name = "page_num", defaultValue = "1") int pageNum,
                                                                                        @RequestParam(name = "page_size", defaultValue = "10") int pageSize,
                                                                                        @RequestParam(name = "type", required = false) Integer type) {
        UserProfile userProfile = LoginUserThread.get();
        return recordService.transferRecordPage(userProfile, pageNum, pageSize, type);
    }

    @ApiOperation("转赠/赠送统计")
    @GetMapping("/transfer/statistics")
    public Result<AdminExchangeItemStatisticsResponse> transferStatistics() {
        UserProfile userProfile = LoginUserThread.get();
        AdminExchangeItemStatisticsResponse response = recordService.transferStatistics(userProfile);
        return Result.success(response);
    }

    @ApiOperation("兑换品转赠赠送排行榜")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page_num", value = "页码", dataType = "number"),
            @ApiImplicitParam(name = "page_size", value = "页记录数", dataType = "number"),
            @ApiImplicitParam(name = "type", value = "赠送类型 1-转赠，2-赠送", dataType = "number"),
    })
    @GetMapping("/transfer/top")
    public Result<PageResult<AdminExchangeItemTransferTopPageResponse>> transferRecordTopList(@RequestParam(name = "page_num", defaultValue = "1") int pageNum,
                                                                                              @RequestParam(name = "page_size", defaultValue = "10") int pageSize,
                                                                                              @RequestParam(name = "type", required = false) Integer type) {
        UserProfile userProfile = LoginUserThread.get();
        return recordService.transferRecordTopList(userProfile, pageNum, pageSize, type);
    }


}
